package testcase.app;


import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONException;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;


import api.app.ResvCapacity;
import common.Host;
import common.TestData;
/**
 * 帮忙医APP获取容量信息接口resvCapacity测试用例
 * @author gaowen
 *
 */
public class TestResvCapacity
{
	/**
	 * 帮忙医APP获取套餐支持机构信息接口ResvCapacity数据驱动
	 * @return 测试数据
	 * @throws IOException
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 */
	@DataProvider(name="Test_GetInstitutionInfo")
	public static String[][] testResvCapacityDataProvider_GetInstitutionInfo() throws IOException, ParserConfigurationException, SAXException
	{
		Host.setup("Test");
		TestData tData=new TestData("app/TestResvCapacity.xml");
		return tData.getParam("GetInstitutionInfo");
	}
	
	/**
	 * 帮忙医APP获取套餐支持机构信息接口ResvCapacity生产环境数据驱动
	 * @return 测试数据
	 * @throws IOException
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 */
	@DataProvider(name="Prod_GetInstitutionInfo")
	public static String[][] prodResvCapacityDataProvider_GetInstitutionInfo() throws IOException, ParserConfigurationException, SAXException
	{
		Host.setup("Prod");
		TestData tData=new TestData("app/TestResvCapacity.xml");
		return tData.getParam("GetInstitutionInfo");
	}
	
	/**
	 * 帮忙医获取机构体检可预约日期resvCapacity数据驱动
	 * @return 测试数据
	 * @throws IOException
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 */
	@DataProvider(name="Test_GetDate")
	public static String[][] testResvCapacityDataProvider_GetDate() throws IOException, ParserConfigurationException, SAXException
	{
		Host.setup("Test");
		TestData tData=new TestData("app/TestResvCapacity.xml");
		return tData.getParam("GetDate");
	}
	
	/**
	 * 帮忙医获取预约容量resvCapacity数据驱动
	 * @return 测试数据
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 * @throws IOException
	 */
	@DataProvider(name="Test_GetCapacity")
	public static String[][] testResvCapacityDataProvider_GetCapacity() throws ParserConfigurationException, SAXException, IOException
	{
		Host.setup("Test");
		TestData tData=new TestData("app/TestResvCapacity.xml");
		return tData.getParam("GetCapacity");
	}
	
	/**
	 * 帮忙医APP获取套餐支持机构信息接口ResvCapacity测试用例
	 * @param casename 用例名
	 * @param packageId 套餐ID
	 * @param attachCodes 获取编码
	 * @param token 用户token
	 * @throws IOException
	 * @throws JSONException
	 */
	@Test(dataProvider="Test_GetInstitutionInfo",groups="Test")
	public void testResvCapacityTestCase_GetInstitutionInfo(String casename,String packageId,String attachCodes,String token) throws IOException, JSONException
	{
		String result=ResvCapacity.get(packageId, attachCodes, token);
		JSONObject jsonResult;
		if (result==null||result.isEmpty())
		{
			jsonResult=null;
		}
		else
		{
			jsonResult=new JSONObject(result);
		}
		
		switch (casename)
		{
			case "GetSuccess":
				Assert.assertFalse(jsonResult.getString("Data").isEmpty());
				break;
			case "PackageIdError":
				Assert.assertTrue(jsonResult.getString("Data").isEmpty());
				break;
			case "PackageIdNull":
				Assert.assertTrue(jsonResult.getString("Data").isEmpty());
				break;
			case "AttachCodesError":
				Assert.assertTrue(jsonResult.getString("Data").isEmpty());
				break;
			case "TokenError":
				Assert.assertNull(result);
				break;
			case "TokenNull":
				Assert.assertNull(result);
				break;
			default:
				break;
		}
	}
	
	/**
	 * 帮忙医APP获取套餐支持机构信息接口ResvCapacity生产环境测试用例
	 * @param casename 用例名
	 * @param packageId 套餐ID
	 * @param attachCodes 获取编码
	 * @param token 用户token
	 * @throws IOException
	 * @throws JSONException
	 */
	@Test(dataProvider="Prod_GetInstitutionInfo",groups="Prod")
	public void prodResvCapacityTestCase_GetInstitutionInfo(String casename,String packageId,String attachCodes,String token) throws IOException, JSONException
	{
		String result=ResvCapacity.get(packageId, attachCodes, token);
		JSONObject jsonResult;
		if (result==null||result.isEmpty())
		{
			jsonResult=null;
		}
		else
		{
			jsonResult=new JSONObject(result);
		}
		
		switch (casename)
		{
			case "GetSuccess":
				Assert.assertFalse(jsonResult.getString("Data").isEmpty());
				break;
			case "PackageIdError":
				Assert.assertTrue(jsonResult.getString("Data").isEmpty());
				break;
			case "PackageIdNull":
				Assert.assertTrue(jsonResult.getString("Data").isEmpty());
				break;
			case "AttachCodesError":
				Assert.assertTrue(jsonResult.getString("Data").isEmpty());
				break;
			case "TokenError":
				Assert.assertNull(result);
				break;
			case "TokenNull":
				Assert.assertNull(result);
				break;
			default:
				break;
		}
	}
	
	/**
	 * 帮忙医获取机构体检可预约日期resvCapacity测试用例
	 * @param casename
	 * @param institutionCode
	 * @param date
	 * @param isVIP
	 * @param token
	 * @throws IOException
	 * @throws JSONException
	 */
	@Test(dataProvider="Test_GetDate",groups="Test")
	public void testResvCapacityTestCase_GetDate(String casename,String institutionCode,String date,String isVIP,String token) throws IOException, JSONException
	{
		String result=ResvCapacity.get(institutionCode, date, isVIP, token);
		JSONObject jsonResult;
		if (result==null||result.isEmpty())
		{
			jsonResult=null;
		}
		else
		{
			jsonResult=new JSONObject(result);
		}
		
		switch (casename)
		{
			case "GetSuccess":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("status"));
				break;
			case "WrongInstitutionCode":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("status"));
				break;
			case "NullInstitutionCode":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("status"));
				break;
			case "DateWrong":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("status"));
				break;
			case "WrongVip":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("status"));
				break;
			case "VipNull":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("status"));
				break;
			case "WrongToken":
				Assert.assertNull(result);;
				break;
			case "TokenNull":
				Assert.assertNull(result);;
				break;
			default:
				break;
		}
	}
	
	/**
	 * 帮忙医获取预约容量resvCapacity测试用例
	 * @param casename 用例名
	 * @param institutionCode 机构编码
	 * @param packageId 套餐ID
	 * @param rqType 容量类型
	 * @param Ldno 落单号
	 * @param isVIP 是否VIP
	 * @param token 用户token
	 * @throws IOException
	 * @throws JSONException
	 */
	@Test(dataProvider="Test_GetCapacity",groups="Test")
	public void testResvCapacityTestCase_GetCapacity(String casename,String institutionCode,String packageId,String rqType,String Ldno,String isVIP,String token) throws IOException, JSONException
	{
		String result=ResvCapacity.get(institutionCode, packageId, rqType, Ldno, isVIP, token);
		
		switch (casename)
		{
			case "GetSuccess":
				Assert.assertNotNull(result);
				break;
			case "InstitutionCodeWrong":
				Assert.assertNotNull(result);
				break;
			case "InstitutionCodeNull":
				Assert.assertNotNull(result);
				break;
			case "PackageWrong":
				Assert.assertNotNull(result);
				break;
			case "PackageNull":
				Assert.assertNotNull(result);
				break;
			case "RqTypeWrong":
				Assert.assertNotNull(result);
				break;
			case "RqTypeNull":
				Assert.assertNotNull(result);
				break;
			case "LdnoWrong":
				Assert.assertNotNull(result);
				break;
			case "LdnoNull":
				Assert.assertNotNull(result);
				break;
			case "VipWrong":
				Assert.assertNotNull(result);
				break;
			case "VipNull":
				Assert.assertNotNull(result);
				break;
			case "TokenWrong":
				Assert.assertNull(result);
			case "TokenNull":
				Assert.assertNull(result);
			default:
				break;
		}
	}
}
